<?php 
require_once("include/conn.php");
require_once("include/config.php");
function tongqibi($shanyear,$jingyear){
	if($shanyear>0){
		if($jingyear>0){
			$tongqibi=round((($jingyear-$shanyear)/$shanyear)*100,2)."%";
			return $tongqibi;
		}else{
			return 0;
		}
	}
	else{
		return 0;
	}
}
$sql_all=$title='';

if(!empty($_GET["title"])){	
	$type=$_GET["type"];	
	$link=$_GET["title"];
	if(isset($link) and  $link==$danyear and $type=="tubiao"){
		//2008年月度概况表
		//罗列出本年度每月的发送吨总和，发送箱总和，运输收入总和，到达箱总和，五定班列总和
		$title=$danyear."年生产任务分析图表";
		$sql_all="SELECT  date_format( tdate,  '%Y-%m'  ) as date,
		sum(yssr) as danyssr,
		sum(fsjzx) as danfsjzx,
		sum(fsd) as fsd ,
		sum(ddjzx) as ddjzx,
		sum(wdblk) as wdbl 
		FROM  bl_scrk 
		WHERE `isdel`='0' and 
		 date_format( tdate,  '%Y'  ) ='".$link."' 
		 group by date_format( tdate,  '%Y%m')";
		 $cn_all=mysql_db_query($db_name,$sql_all);	
		}
	else if(isset($link) and  $link==$danyear and $type=="gaikuang"){
		//2008年月度概况表
		//罗列出本年度每月的发送吨总和，发送箱总和，运输收入总和，到达箱总和，五定班列总和
		$title=$danyear."年月度概况表";
		$sql_all="SELECT  date_format( tdate,  '%Y-%m'  ) as date,
		sum(yssr) as danyssr,
		sum(fsjzx) as danfsjzx,
		sum(fsd) as fsd ,
		sum(ddjzx) as ddjzx,
		sum(wdblk) as wdbl 
		FROM  bl_scrk 
		WHERE `isdel`='0' and 
		 date_format( tdate,  '%Y'  ) ='".$link."' 
		 group by date_format( tdate,  '%Y%m')";
		 $cn_all=mysql_db_query($db_name,$sql_all);	
	}
	else if(isset($link) and $type=="rili"){
		//2008年生产任务日历报表
		//罗列出本年度每月每天的发送吨，发送箱，运输收入，到达箱，五定班列
		$title=$danyear."年生产任务日历报表 ";
		$sql_all="SELECT *  FROM  `bl_scrk` where  isdel='0' and date_format(tdate, '%Y%m') ='".$link."' order by tdate  ";
		$cn_all=mysql_db_query($db_name,$sql_all);
		if($num=mysql_num_rows($cn_all)){
			$url="?nname=9";
			$c_name="任务指标";			
		}/*else{
			self("无此记录!","fen_lan.php?nname=9");		
		}*/			
	}
//echo $sql_all;exit;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?></title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
}
.redtt{
	color:red;
	font-size:18px;
}
-->
</style></head>
<body>
 <?php include("include/dttop.php");
  if($link==$danyear and $type=="gaikuang"){
  ?>
<TABLE width=775 height=50 border=1 align="center" cellPadding=5 
cellSpacing=3 borderColor=#336699 bgColor=#e1f0ff style="BORDER-COLLAPSE: collapse">
  <TBODY>
  <TR> 
    <TD colspan="8"><P class=MsoNormal style="TEXT-ALIGN: center" align=center><B><SPAN 
      style="FONT-SIZE: 18pt; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-hansi-font-family: 'Times New Roman'; mso-ascii-font-family: 'Times New Roman'"><?php echo $danyear."年月度概况表"; ?></SPAN></B></P></TD>
</TR>
  <TR>
    <TD align="center">月份</TD>
    <TD colspan="2" align="center">运输收入</TD>
    <TD colspan="2" align="center">发送箱</TD>
    <TD align="center">&nbsp;</TD>
    <TD align="center">&nbsp;</TD>
    <TD align="center">&nbsp;</TD>
  </TR>
  <TR>  
    <TD width="138" align="center">&nbsp;</TD>
    <TD width="112" align="center">今年数据<br>(万元)</TD>
	<TD width="112" align="center">上年同比<br></TD>
	<TD width="119" align="center">今年数据<br>(TEU)</TD>
	<TD width="119" align="center">上年同比<br></TD>
    <TD width="103" align="center">发送吨<br>(吨)</TD>
    <TD width="114" align="center">到达箱<br>(TEU)</TD>
    <TD width="94" align="center">五定班列<br>(列)</TD>
  </TR>
<?php 
	$rr1=0;
	$rr2=0;
	$rr3=0;
	$rr4=0;
	$rr5=0;
	
	$next_yssrall=0;
	$next_fsxall=0;
	
while($row_all = mysql_fetch_array($cn_all)){ 	 
	//累加相关数据
	$rr1+=numberout($row_all[1]);
	$rr2+=$row_all[2];
	$rr3+=$row_all[3];
	$rr4+=$row_all[4];
	$rr5+=numberout($row_all[5]);	
	$rrdate=cdate($row_all[0]);	
	$da=split("-",$row_all[0]);
	$daa=intval($da[0]-1)."-".$da[1];
	 //与2008年比期比2007年月度概况表
	//罗列出本年度当月的发送吨总和，发送箱总和
	$sql_next="SELECT  date_format( tdate,  '%Y-%m'  ) as date,
	sum(yssr) as danyssr,
	sum(fsjzx) as danfsjzx
	FROM  bl_scrk 
	WHERE `isdel`='0' and 
	 date_format( tdate,  '%Y-%m'  ) ='".$daa."' 
	 group by date_format( tdate,  '%Y%m')";
	$cn_next=mysql_db_query($db_name,$sql_next);
	//判断力当月上年同期数据，并作相应处理
	if($row_next=mysql_fetch_row($cn_next)){
		$next_yssr=$row_next[1];
		$next_fsx=$row_next[2];
	}else{
		$next_yssr=0;
		$next_fsx=0;
	}
	//
	
	
	//累加上年同期数据
	$next_yssrall+=$next_yssr;
	$next_fsxall+=$next_fsx;
?>
  <TR>  
    <TD align="center"><?php echo cdate($row_all[0]) ?></TD>
	<TD align="center"><?php echo numberout($row_all[1]) ?></TD>
    <TD align="center"><?php echo tongqibi($next_yssr,$row_all[1]) ?></TD>
    <TD align="center"><?php echo chtowan(numberout($row_all[2])) ?></TD>
    <TD align="center"><?php echo tongqibi($next_fsx,$row_all[2]) ?></TD>
    <TD align="center"><?php echo formatfsd(numberout($row_all[3])) ?></TD>
	<TD align="center"><?php echo chtowan(numberout($row_all[4])) ?></TD>
    <TD align="center"><?php echo chtowan(numberout($row_all[5])) ?></TD>
  </TR>
<?php }?>
<TR>  
    <TD align="center" class="redtt"><?php echo $rrdate."<br>截止数据合计" ?></TD>
    <TD align="center" class="redtt"><?php echo $rr1 ?></TD>
	<TD align="center" class="redtt"><?php //echo tongqibi($next_yssrall,$rr1) ?></TD>
    <TD align="center" class="redtt"><?php echo chtowan($rr2) ?></TD>	    
    <TD align="center" class="redtt"><?php //echo tongqibi($next_fsxall,$rr2) ?></TD>
    <TD align="center" class="redtt"><?php echo formatfsd($rr3) ?></TD>
	<TD align="center" class="redtt"><?php echo chtowan($rr4) ?></TD>
    <TD align="center" class="redtt"><?php echo chtowan($rr5) ?></TD>
  </TR>
</TBODY></TABLE>
<?php 
}else if($type=="rili"){
?>
<TABLE width=775 height=50 border=1 align="center" cellPadding=5 
cellSpacing=3 borderColor=#336699 bgColor=#e1f0ff style="BORDER-COLLAPSE: collapse">
  <TBODY>
  <TR> 
    <TD colspan="6"><P class=MsoNormal style="TEXT-ALIGN: center" align=center><B><SPAN 
      style="FONT-SIZE: 18pt; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-hansi-font-family: 'Times New Roman'; mso-ascii-font-family: 'Times New Roman'"><?php echo $row_all[1] ?></SPAN></B></P></TD>
</TR>
<TR>  
    <TD width="138" align="center">
	指标发布日期</TD>
    <TD width="112" align="center">运输收入(万元)</TD>
	<TD width="119" align="center">发送箱(TEU)</TD>
    <TD width="103" align="center">发送吨(吨)</TD>
    <TD width="114" align="center">到达箱(TEU)</TD>
    <TD width="94" align="center">五定班列(列)</TD>
  </TR>
<?php 
	$rr1=0;
	$rr2=0;
	$rr3=0;
	$rr4=0;
	$rr5=0;
	
while($row_all = mysql_fetch_array($cn_all)){ 
	$rr1+=numberout($row_all[3]);
	$rr2+=$row_all[4];
	$rr3+=$row_all[10];
	$rr4+=$row_all[5];
	$rr5+=numberout($row_all[7]);
	
	$rrdate=$row_all[2];
?>
  <TR>  
    <TD align="center"><?php echo $row_all[2] ?></TD>
    <TD align="center"><?php echo round($row_all[3],1) ?></TD>
    <TD align="center"><?php echo round($row_all[4],1) ?></TD>
    <TD align="center"><?php echo round($row_all[10],1) ?></TD>
	<TD align="center"><?php echo round($row_all[5],1) ?></TD>
    <TD align="center"><?php echo round(numberout($row_all[7]),1) ?></TD>
  </TR>
<?php }?>
<TR>  
    <TD align="center" class="redtt"><?php echo $rrdate."<br>截止数据合计" ?></TD>
    <TD align="center" class="redtt"><?php echo round($rr1,0) ?></TD>
    <TD align="center" class="redtt"><?php echo round($rr2,0) ?></TD>
    <TD align="center" class="redtt"><?php echo round($rr3/10000,0) ?>万</TD>
	<TD align="center" class="redtt"><?php echo round($rr4,0) ?></TD>
    <TD align="center" class="redtt"><?php echo round($rr5,0) ?></TD>
  </TR>
</TBODY></TABLE>
<?php }?>
<TABLE width=775 border=0 align="center" cellPadding=0 cellSpacing=0 borderColor=#111111 bgColor=#3399cc id=AutoNumber27 style="BORDER-COLLAPSE: collapse">
  <TBODY>
  <TR>
    <TD align=middle width=100%>
      <TABLE width=100% height=37 
      border=0  cellPadding=0 cellSpacing=0 
      borderColor=#111111 id=AutoNumber36 
      style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: 1px solid; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; BORDER-COLLAPSE: collapse">
        <TBODY>
        <TR>
          <TD width=100% height=37>
            <DIV align=center>
            <CENTER>
            <TABLE width=100% border=0 align="center" cellPadding=0 cellSpacing=0 borderColor=#111111 id=AutoNumber37 style="BORDER-COLLAPSE: collapse">
              <TBODY>
              <TR>
                <TD width=299>
                  <P align=center><FONT color=#ffffff><A style="TEXT-DECORATION: none" href="javascript:window.print()" >打印</a></FONT></P></TD>
                <TD width=209>
                  <P align=center><FONT color=#ffffff><A style="TEXT-DECORATION: none" href="javascript:window.close()">关闭</a></FONT></P></TD>
                <TD width=265>
<P align=center><A style="TEXT-DECORATION: none" 
                  href="./">返回首页</A></P></TD></TR></TBODY></TABLE></CENTER></DIV></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></body>
</html>
<?php 
	
}
else{
	back("记录不存在!");	
}
?>